// pages/watch/watch.js
const app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
  },
  bindKeyInput: function (e) {
    this.setData({
      inputValue: e.detail.value
    })
   
  },
  gonewwatcher() {
    wx.navigateTo({
      url: "/pages/newwatcher/newwatcher"
    })
  }, 
  gomodifywatchar(e) {
    console.log('99999')
    console.log(e)
    var viewer = e.currentTarget.dataset.viewer;
    var phone = e.currentTarget.dataset.userphone;
    var identity = e.currentTarget.dataset.identity;
    wx.navigateTo({
      url: "/pages/modifywatchar/modifywatchar"
    })
    wx.setStorage({
      key: "modifyviewer",
      data: viewer
    })
    wx.setStorage({
      key: "modifyphone",
      data: phone
    })
    wx.setStorage({
      key: "modifyidentity",
      data: identity
    })
  },
  
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let self = this;
    self.getwatchList()
  },
  //获取观影人列表数据
  getwatchList: function () {
    let self = this;
    let userInfo = app.globalData.userInfo;

    wx.request({
      url: "http://localhost:3000/showViewer",
      method: 'POST',
      data: {
        userName: userInfo.nickName
      },
      success(res) {
        console.log("111111111")
        console.log(res.data)
        let result = res.data;
        if (result) {
          //赋值
          self.setData({
            watchList: result
          })
        }
      }
    })
  },
  // 删除
  delete(e) {
    let _self = this;
    let userInfo = app.globalData.userInfo;
    console.log(e);
    let viewer = e.currentTarget.dataset.viewer;
    console.log(viewer)
    wx.showModal({
      title: '提示',
      content: '确定删除吗？',
      success(res) {
        if (res.confirm) {
          let self = this;
          wx.request({
            url: "http://localhost:3000/deleteViewer",
            method: 'POST',
            data: {
              userName: userInfo.nickName,
              viewer: viewer
            },
            success(res) {
              console.log(res.data)
              let result = res.data;
              console.log(result)
              wx.showToast({
                title: '成功',
                icon: 'success',
                duration: 2000
              }),
              _self.getwatchList()

            }
          })
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})